using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QLKS.HeThongBUS;

namespace QLKS
{
    public partial class DSPhong : DevComponents.DotNetBar.Office2007Form
    {
        public DSPhong()
        {
            InitializeComponent();
        }

       

        private void DSPhong_Load(object sender, EventArgs e)
        {
            //381
            this.Width = 381;
            HienThi();
            DataTable dt = PH_BUS.DSLoaiPhong();
            cbblp.DataSource = dt;
            cbblp.DisplayMember="Tên Loại Phòng";
            cbblp.ValueMember = "Mã Loại Phòng";
            DataTable dt1 = QD_BUS.ThongTinKS();
            DataRow dr = dt1.Rows[0];
            int tang = Int32.Parse(dr["SoTang"].ToString());
            

            for (int i = 1; i <= tang; i++)
            {
                cbbtang.Items.Add(i);
            }
            cbbtang.SelectedItem = 1;
            
        }



        void HienThi()
        {
            DataTable dt = PH_BUS.DSPhong();
            grvdsp.DataSource = dt;
            grvdsp.Columns[0].Width = 85;
            grvdsp.Columns[1].Width = 85;
            grvdsp.Columns[2].Width = 85;
            grvdsp.Columns[3].Width = 50;
            grvdsp.Columns[4].Visible = false;
            
            
        }

        private void btntracuu_Click(object sender, EventArgs e)
        {
            this.Width = 675;
        }

        private void ckboxsp_CheckedChanged(object sender, EventArgs e)
        {
            if (ckboxsp.Checked == true)
            {
                txtsp.Enabled = true;
            }
            else if (ckboxsp.Checked == false)
            {
                txtsp.Enabled = false;
            }
        }

        private void ckboxlp_CheckedChanged(object sender, EventArgs e)
        {
            if (ckboxlp.Checked == true)
            {
                cbblp.Enabled = true;
            }
            else if (ckboxlp.Checked == false)
            {
                cbblp.Enabled = false;
            }
        }

        private void ckboxtang_CheckedChanged(object sender, EventArgs e)
        {
            if (ckboxtang.Checked == true)
            {
                cbbtang.Enabled = true;
            }
            else if (ckboxtang.Checked == false)
            {
                cbbtang.Enabled = false;
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                DataTable dt = PH_BUS.DSPhongTrong();
                grvdsp.DataSource = dt;
            }
            else if (checkBox1.Checked== false)
            {
                HienThi();
                
            }
        }

    #region xu ly nut tim kiem
        string dk1;
        string dk2;
        string dk3;
        private void buttonX1_Click(object sender, EventArgs e)
        {
            
            if (txtsp.Text != "" && ckboxsp.Checked == true)
            {
                dk1 = "And MaPhong = '" + txtsp.Text.ToString() + "'";
            }
            if (txtsp.Text == "" || ckboxsp.Checked == false)
            {
                dk1 = "";
            }
            if (ckboxlp.Checked == true)
            {
                dk2 = "And LoaiPhong='" + cbblp.SelectedValue.ToString() + "'";
                
            }
            if (ckboxlp.Checked == false)
            {
                dk2 = "";
            }
            if (ckboxtang.Checked == true)
            {
                dk3 = "And Tang='" + cbbtang.SelectedItem.ToString() + "'";
                
            }
            if (ckboxtang.Checked == false)
            {
                dk3 = "";
            }
            DataTable dt = PH_BUS.TraCuuPhong(dk1, dk2, dk3);
            grvdsp.DataSource = dt;
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("Không tìm thấy dữ liệu theo yêu cầu", "Thông báo");
            }

        }
    
    #endregion

    }
}